package com.fulei.device;

import com.bjfl.saleManager.util.LogUtil;
import com.fulei.logic.FuleiFightControl;

public class ControlPanelDevice
{
  private String deviceType;
  private String comNo;
  private String baudRate;
  
  public ControlPanelDevice(String devType, String com, String brn)
  {
    this.deviceType = devType;
    this.comNo = com;
    this.baudRate = brn;
  }
  
  public int ResetKey()
  {
    int return_data = 0;
    try
    {
      if ("CONTROLPANEL1".equals(this.deviceType))
      {
        FuleiFightControl.comNo = this.comNo;
        FuleiFightControl.baudRate = this.baudRate;
        
        return_data = FuleiFightControl.ResetKey();
      }
    }
    catch (Exception ex)
    {
      LogUtil.writeExceptionLog("复位控制板:" + ex.getMessage());
      return_data = -1;
    }
    return return_data;
  }
  
  public int ControlFlash(int flashNo, int flashMode, int flashSpeed)
  {
    int return_data = 0;
    try
    {
      if ("CONTROLPANEL1".equals(this.deviceType))
      {
        FuleiFightControl.comNo = this.comNo;
        FuleiFightControl.baudRate = this.baudRate;
        
        return_data = FuleiFightControl.FlashKey(flashNo, flashMode, flashSpeed);
      }
    }
    catch (Exception ex)
    {
      LogUtil.writeExceptionLog("控制闪灯异常:" + ex.getMessage());
      return_data = -1;
    }
    return return_data;
  }
  
  public int CutPaperFlash()
  {
    int return_data = 0;
    try
    {
      if ("CONTROLPANEL1".equals(this.deviceType))
      {
        FuleiFightControl.comNo = this.comNo;
        FuleiFightControl.baudRate = this.baudRate;
        
        return_data = FuleiFightControl.CutPaperFlashKey();
      }
    }
    catch (Exception ex)
    {
      LogUtil.writeExceptionLog("出货口闪灯异常:" + ex.getMessage());
      return_data = -1;
    }
    return return_data;
  }
  
  public int[] Query()
  {
    int[] return_data = new int[2];
    try
    {
      if ("CONTROLPANEL1".equals(this.deviceType))
      {
        FuleiFightControl.comNo = this.comNo;
        FuleiFightControl.baudRate = this.baudRate;
        return_data = FuleiFightControl.QuerySensorStatus();
      }
    }
    catch (Exception ex)
    {
      LogUtil.writeExceptionLog("传感器接口异常:" + ex.getMessage());
    }
    return return_data;
  }
  
  public int[] QuerySensorStatus()
  {
    int[] return_data = new int[4];
    try
    {
      if ("CONTROLPANEL1".equals(this.deviceType))
      {
        FuleiFightControl.comNo = this.comNo;
        FuleiFightControl.baudRate = this.baudRate;
        return_data = FuleiFightControl.QueryControlStatus();
      }
    }
    catch (Exception ex)
    {
      LogUtil.writeExceptionLog("查询传感器和震动报警器状态接口异常:" + ex.getMessage());
    }
    return return_data;
  }
  
  public int fightFickerDeviceControl(byte[] speed, byte colors)
  {
    int return_data = 0;
    try
    {
      if ("CONTROLPANEL1".equals(this.deviceType))
      {
        FuleiFightControl.comNo = this.comNo;
        FuleiFightControl.baudRate = this.baudRate;
        return_data = FuleiFightControl.fightFickerControl(speed, colors);
      }
    }
    catch (Exception ex)
    {
      LogUtil.writeExceptionLog("灯带控制板:" + ex.getMessage());
      return_data = -1;
    }
    return return_data;
  }
}
